<template>
  <el-tabs v-model="activeName" @tab-click="handleClick">
    <el-tab-pane label="登录账户设置" name="first">
      <el-form
        ref="ruleForm"
        style="width :500px;margin：0  auto"
        :model="ruleForm"
        :rules="rules"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="ruleForm.username" />
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input v-model="ruleForm.password" type="password" />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
          >保存</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
    <el-tab-pane label="个人详情" name="userInfo">
      <user-info />
      <!-- <component :is="activeName" /> -->
    </el-tab-pane>
    <el-tab-pane label="岗位信息" name="jobInfo">
      <job-info />
      <!-- <component :is="activeName" /> -->
    </el-tab-pane>
  </el-tabs>
</template>
<script>
// import { getUserMsg, updateUserMsg } from '@/api/employees'

import { updateUserMsg } from '@/api/employees'

import userInfo from './components/user-info.vue'
import jobInfo from './components/job-info.vue'

// import mixin from '@/mixins'
export default {
  components: {
    userInfo,
    jobInfo
  },
  // mixins: [mixin],
  data() {
    return {
      // user: 'userInfo',
      // job: 'jobInfo',
      activeName: 'first',
      ruleForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 6, message: '长度在 3 到 6个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getUser()
  },

  methods: {
    handleClick(tab, event) {
      console.log(tab, event)
    },
    // async getUser() {
    //   this.ruleForm = await getUserMsg(this.$route.params.id)
    // },

    submitForm(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          await updateUserMsg(this.ruleForm)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
